<p>This rule raises an issue when code converts a Set to an array using the spread operator and then accesses the <code>length</code> property,
instead of directly using the Set’s <code>size</code> property.</p>
<h2>Why is this an issue?</h2>
<p>When you need to get the number of elements in a Set, accessing the <code>size</code> property directly is more efficient than first converting the
Set to an array.</p>
<p>The pattern <code>[…​new Set(array)].length</code> creates unnecessary overhead because:</p>
<ul>
  <li> The spread operator <code>…​</code> creates a new array from the Set </li>
  <li> This array creation requires additional memory allocation </li>
  <li> The operation takes more time than simply reading the <code>size</code> property </li>
</ul>
<p>Sets have a built-in <code>size</code> property that provides the exact same information without any conversion. This property is specifically
designed for this purpose and is both faster and more semantically correct.</p>
<p>Using <code>Set#size</code> directly makes your code more readable because it clearly expresses the intent: you want to know how many unique
elements there are, not create an array.</p>
<h3>What is the potential impact?</h3>
<p>This issue causes unnecessary performance overhead due to array creation and memory allocation. While the impact may be minimal for small datasets,
it can become significant when working with large Sets or when this operation is performed frequently in loops or hot code paths.</p>
<h3>How to fix?</h3>
<p>Replace the array conversion and length access with direct access to the Set’s size property.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
function isUnique(array) {
	return [...new Set(array)].length === array.length; // Noncompliant
}
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
function isUnique(array) {
	return new Set(array).size === array.length;
}
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-set-size.md">prefer-set-size</a> </li>
  <li> MDN - Set.prototype.size - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/size">Official
  documentation for the Set size property</a> </li>
  <li> MDN - Set - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">Complete reference for JavaScript
  Set objects</a> </li>
</ul>
